﻿namespace EMall.Domain
{
    public abstract class AggregateRoot<TKey> : Entity<TKey>, IAggregateRoot<TKey>
    {
        public IReadOnlyList<IDomainEvent> DomainEvents => _domainEvents.AsReadOnly();
        protected List<IDomainEvent> _domainEvents = new List<IDomainEvent>();
        protected AggregateRoot() { }
        protected AggregateRoot(TKey id) : base(id) { }
        protected virtual void AddDomainEvent(IDomainEvent eventItem) => _domainEvents.Add(eventItem);
        public virtual void ClearDomainEvents() => _domainEvents.Clear();
    }
}
